<?php

/* @var $this yii\web\View */
/* @var $model backend\models\ProjectEase */
/* @var $form yii\bootstrap\ActiveForm */
use yii\bootstrap\ActiveForm;
use kartik\detail\DetailView;
use backend\models\Country;
use backend\models\Tags;
use yii\helpers\Url;
use yii\widgets\Pjax;


$modelCountry = new Country();
$arr_provinces = $modelCountry->getProvinces();
if ($model->province) {
    $province = implode('', $modelCountry->getProvinces("id =" . $model->province));
} else {
    $province = '';
}
if ($model->city) {
    $city = implode('', $modelCountry->getProvinces("id=" . $model->city));
} else {
    $city = '';
}

$arr_package = $model->getAllPackages();
if ($model->package_id) {
    $package = $model->package->title;
} else {
    $package = '';
}

if ($model->tag) {
    $arr_tag = $model->tag;
    $arr_tag_tag = [];
    if (is_array($arr_tag) && count($arr_tag) > 0) {
        foreach ($arr_tag as $item) {
            $arr_tag_tag[] = Tags::findOne(['id' => $item])->title;
        }
        $tags = implode(',', $arr_tag_tag);
    } else {
        $tags = '';
    }
} else {
    $tags = '';
}


?>
<div class="container">
    <div class="project-ease-form">

        <?php
        Pjax::begin(['id' => 'project_form']);
        echo DetailView::widget([
            'model' => $model,
            'condensed' => true,
            'hover' => true,
            'mode' => 'edit',
            'panel' => [
                'heading' => '项目信息',
                'headingOptions' => ['template' => '{title}'],
                'type' => DetailView::TYPE_INFO,
                'footer' => '<span class="glyphicon glyphicon-pencil"></span>',
                'footerOptions' => ['class' => 'panel-heading', 'tag' => 'h4', 'template' => '{buttons}{title}']
            ],
            'formOptions' => ['options' => ['data-pjax' => true],],
            'hideIfEmpty' => false,//如果有空字段则隐藏
            'buttons1' => '{update}',
            'buttons2' => '{view} {reset} {save}',
            'updateOptions' => ['label' => '<span class="btn btn-info">编辑</span>'],
            'viewOptions' => ['label' => '<span class="btn btn-info">查看</span>'],
            'saveOptions' => ['label' => $model->id == '' ? '<span class="btn btn-info">保存</span>' : (($model->id && $model->package->owner == Yii::$app->user->id) ? '<span class="btn btn-info">保存</span>' : '')],
            'resetOptions' => ['label' => '<span class="btn btn-info">重置</span>'],
            'attributes' => [
//                'title',
                [
                    'attribute' => 'package_id',
                    'type' => DetailView::INPUT_SELECT2,
                    'value' => $package,
                    'label' => "<span class='text-danger'>" . $model->getAttributeLabel('package_id') . "*</span>",
                    'widgetOptions' => [
                        'data' => $arr_package,
                        'options' => ['placeholder' => '选择资产包 ...'],
                        'pluginOptions' => [
                            'allowClear' => true
                        ]
                    ],
                    'inputWidth' => '30%'
//                    'valueColOptions' => ['style' => 'width:30%']
                ],
                [
                    'attribute' => 'level',
                    'type' => DetailView::INPUT_RADIO_LIST,
                    'items' => Yii::$app->params['project_ease_level'],
                    'value' => Yii::$app->params['project_ease_level'][$model->level],
                    'valueColOptions' => ['class' => 'form-inline']
                ],
                [
                    'attribute' => 'category',
                    'type' => 'radioList',
                    'items' => Yii::$app->params['project_category'],
                    'value' => Yii::$app->params['project_category'][$model->category],
                    'valueColOptions' => ['class' => 'form-inline'],
                    'label' => "<span class='text-danger'>" . $model->getAttributeLabel('category') . "*</span>"
                ],
                [
                    'attribute' => 'borrower',
                    'label' => "<span class='text-danger'>" . $model->getAttributeLabel('borrower') . "*</span>"
                ],
                [
                    'columns' => [
                        [
                            'attribute' => 'province',
                            'type' => DetailView::INPUT_SELECT2,
                            'value' => $province,
                            'widgetOptions' => [
                                'data' => $arr_provinces,
                                'options' => ['placeholder' => '选择省份 ...'],
                                'pluginOptions' => [
                                    'allowClear' => true
                                ]
                            ],
                            'label' => "<span class='text-danger'>" . $model->getAttributeLabel('province') . "*</span>",
                            'valueColOptions' => ['style' => 'width:30%']
                        ],
                        [
                            'attribute' => 'city',
                            'type' => DetailView::INPUT_DEPDROP,
                            'widgetOptions' => [
                                'type' => 2,
                                'pluginOptions' => [
                                    'depends' => ['projectease-province'],
                                    'placeholder' => '选择城市...',
                                    'url' => Url::to(['/country/get-city', 'province' => 'projectease-province']),
                                ]
                            ],
                            'value' => $city,
                        ],
                    ],
                ],
                [
                    'columns' => [
                        [
                            'attribute' => 'principal', 'valueColOptions' => ['style' => 'width:30%'], 'format' => 'decimal',
                            'label' => "<span class='text-danger'>" . $model->getAttributeLabel('principal') . "*</span>",
                        ],
                        'interest:decimal',
                    ],
                ],
                [
                    'attribute' => 'is_suit',
                    'type' => DetailView::INPUT_RADIO_LIST,
                    'items' => Yii::$app->params['is_suit'],
                    'value' => Yii::$app->params['is_suit'][$model->is_suit],
                    'valueColOptions' => ['class' => 'form-inline']
                ],
                [
                    'attribute' => 'suit',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'execution',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'tag',
                    'type' => DetailView::INPUT_SELECT2,
                    'widgetOptions' => [
                        'data' => Tags::getAllTags(),
                        'options' => ['placeholder' => '选择标签'],
                        'pluginOptions' => [
                            'allowClear' => true,
                            'multiple' => true,
                        ]
                    ],
                    'value' => $tags,
                ],
                [
                    'attribute' => 'tagTitle',
                    'label' => '自定义标签',
                    'options' => ['placeholder' => '住宅，土地等等，多个标签用逗号隔开']
                ],
                [
                    'attribute' => 'source',

                    'type' => DetailView::INPUT_RADIO_LIST,
                    'items' => Yii::$app->params['project_ease_source'],
                    'value' => Yii::$app->params['project_ease_source'][$model->source],
                    'valueColOptions' => ['class' => 'form-inline', 'style' => 'vlign:center']
                ],
                [
                    'attribute' => 'detail',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],
                [
                    'attribute' => 'note',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => '沟通情况'],
                ],
                [
                    'attribute' => 'follow',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => '过会备注'],
                ],//过会备注
                [
                    'attribute' => 'is_highlights',
//                    'label' => '',
                    'format' => 'raw',
                    'value' => $model->is_highlights ? '<span class="label label-success">是</span>' : '<span class="label label-danger">否</span>',
                    'type' => DetailView::INPUT_SWITCH,
                    'widgetOptions' => [
                        'pluginOptions' => [
                            'onText' => '是',
                            'offText' => '否',
                        ]
                    ]
                ],
                [
                    'attribute' => 'highlights',
                    'type' => DetailView::INPUT_TEXTAREA,
                ],

                [
                    'attribute' => 'stakeholders',
                    'label' => "<span class='text-danger'>" . $model->getAttributeLabel('stakeholders') . "*</span>",
                ],
                ['attribute' => 'management_status', 'type' => 'radioList', 'items' => Yii::$app->params['operation_status'], 'value' => Yii::$app->params['operation_status'][$model->management_status], 'valueColOptions' => ['class' => 'form-inline']],
                ['attribute' => 'stakeholders_status', 'options' => ['placeholder' => implode(',', Yii::$app->params['operation_status'])]],
                ['columns' => [['attribute' => 'mortgage_principal', 'valueColOptions' => ['style' => 'width:30%'], 'format' => 'decimal'], 'mortgage_interest:decimal',]],
//                'mortgage_owner',
                [
                    'attribute' => 'mortgage_type',
                    'type' => DetailView::INPUT_CHECKBOX_LIST,
                    'items' => Yii::$app->params['project_mortgage_type'],
                    'valueColOptions' => ['class' => 'form-inline'],
                    'value' => '',
                ],
//                'other_warrants_code', 'mortgage_address',
//                ['columns' => [['attribute' => 'mortgage_building_area', 'valueColOptions' => ['style' => 'width:30%']], 'mortgage_land_area',]],
                [
                    'attribute' => 'mortgage_detail',
                    'type' => DetailView::INPUT_TEXTAREA,
                    'options' => ['placeholder' => '说明抵押物权属人/他项权证号/抵押物地址/建筑面积/土地面积等其他情况'],
                ]
            ]
        ]);
        Pjax::end();
        ?>

    </div>
</div>

